/**查询全部用户**/
function queryRoom() {
    $.ajax({
        type: "GET",
        url: "rest/room/list",
        dataType: "json",
        success: function (data) {
            var roomList = data.data;
            if (roomList.lenght == 0) {
                $("#show_list").html("暂时查不到您要的数据！");
            } else {
                var roomListHtml = "<tr><th><input id='checked-all' type='checkbox'><label>全选</label></th><th>班级名称</th><th>班级人数</th><th>班主任</th><th>操作</th></tr>";
                $.each(roomList, function (i, n) {
                    i += 1;
                    roomListHtml = roomListHtml + "<tr><td class='list-id'><input type='checkbox'><label>"
                        + i + "</label></td><td>"
                        + n.name + "</td><td>"
                        + n.number + "</td><td>"
                        + n.teacher + "</td><td class='user-edit'><a  class='editBtn' data-id='"
                        + n.id + "'>编辑</a><a class='deleteBtn'  data-id='"
                        + n.id + "'>删除</a></td></tr>";
                });
                $("#show_list").html(roomListHtml);
                $(".deleteBtn").click(function () {
                    delRoom($(this).attr("data-id"));
                });
                $(".editBtn").click(function () {
                    updateRoom($(this).attr("data-id"));
                })

            }
        }
    });
}

/**
 * @decription:添加案例
 *  @param：#submit 提交
 */

function addRoom() {
    window.location.href = "rest/room/addRoom";//跳转到添加页面

}

/**
 * @decription:删除案例
 */
function delRoom(roomId) {
    var param = "roomId=" + roomId;
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "rest/room/del",
        data: param,
        success: function () {
            queryRoom();
        }
    });
}

/**
 * @decription:更新案例
 */
function updateRoom(roomId) {
    window.location.href = "rest/room/editorRoom" + "?id=" + roomId;

}
queryRoom();